exercise-21-csu

Author

Eleanor Lindsey

Uploading the Data from USGS site 06752260

options(repos = c(CRAN = "https://cran.rstudio.com/"))
library(tsibble)
Registered S3 method overwritten by 'tsibble':
  method               from 
  as_tibble.grouped_df dplyr

Attaching package: 'tsibble'
The following objects are masked from 'package:base':

    intersect, setdiff, union
library(dataRetrieval)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
# Example: Cache la Poudre River at Mouth (USGS site 06752260)
poudre_flow <- readNWISdv(siteNumber = "06752260",    # Download data from USGS for site 06752260
                          parameterCd = "00060",      # Parameter code 00060 = discharge in cfs)
                          startDate = "2013-01-01",   # Set the start date
                          endDate = "2023-12-31") |>  # Set the end date
  renameNWISColumns() |>                              # Rename columns to standard names (e.g., "Flow", "Date")
  mutate(Date = yearmonth(Date)) |>                   # Convert daily Date values into a year-month format (e.g., "2023 Jan")
  group_by(Date) |>                                   # Group the data by the new monthly Date
  summarise(Flow = mean(Flow))                       # Calculate the average daily flow for each month
GET:https://waterservices.usgs.gov/nwis/dv/?site=06752260&format=waterml%2C1.1&ParameterCd=00060&StatCd=00003&startDT=2013-01-01&endDT=2023-12-31

Converting to a Tsibble

poudre_tsibble<-as_tsibble(poudre_flow)
Using `Date` as index variable.

Plotting the Time Series

library(ggplot2)
library(plotly)

Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':

    last_plot
The following object is masked from 'package:stats':

    filter
The following object is masked from 'package:graphics':

    layout
poudre_plot<-ggplot(poudre_tsibble, aes(x=Date, y=Flow))+
  geom_line(color="cornflowerblue")+
  labs(title="Flow Data from the Cache La Poudre USGS site 06752260",
       x="Date",
       y="Flow (cfs)")
ggplotly(poudre_plot)

Sub Series

install.packages("feasts")

The downloaded binary packages are in
    /var/folders/95/7bppnrhs19z4vp_sdb0lv9zr0000gn/T//Rtmp4JDb8x/downloaded_packages
library(feasts)
Loading required package: fabletools
gg_subseries(poudre_tsibble)
Plot variable not specified, automatically selected `y = Flow`

Description:

I see there is a defined pattern of high stream flow in May and June. Stream Flow is noticeably low from November to February. This makes sense as Colorado gets a lot of rain during the spring months including snow melt. This increase in precipitation increases stream discharge which will cause these spikes in data. Comparatively, the patterns of low stream flow can be explained by the periods of snow precipitation.

Decompose

poudre_decompose<-poudre_tsibble%>%
  model(STL(Flow ~ season(window="periodic")))%>%
  components()
poudre_decompose
# A dable: 132 x 7 [1M]
# Key:     .model [1]
# :        Flow = trend + season_year + remainder
   .model                  Date   Flow trend season_year remainder season_adjust
   <chr>                  <mth>  <dbl> <dbl>       <dbl>     <dbl>         <dbl>
 1 "STL(Flow ~ season… 2013 Jan 1.81e1  13.0      -173.      179.           192.
 2 "STL(Flow ~ season… 2013 Feb 1.80e1  42.0      -176.      152.           194.
 3 "STL(Flow ~ season… 2013 Mar 8.21e0  70.9      -178.      115.           186.
 4 "STL(Flow ~ season… 2013 Apr 5.94e0 101.       -121.       26.5          127.
 5 "STL(Flow ~ season… 2013 May 3.33e2 131.        641.     -439.          -308.
 6 "STL(Flow ~ season… 2013 Jun 3.00e2 157.        778.     -636.          -478.
 7 "STL(Flow ~ season… 2013 Jul 7.56e1 184.        -57.4     -51.2          133.
 8 "STL(Flow ~ season… 2013 Aug 4.88e1 208.       -114.      -45.8          162.
 9 "STL(Flow ~ season… 2013 Sep 1.09e3 232.        -74.3     927.          1160.
10 "STL(Flow ~ season… 2013 Oct 1.46e2 276.       -150.       19.3          296.
# ℹ 122 more rows
poudre_decompose_plot<-ggplot(poudre_decompose, aes(x=Date, y=season_adjust))+
  geom_line(color="forestgreen")+
  labs(title="Seaonsality and the Cache La Poudre", x="Date", y="Seasonality")
ggplotly(poudre_decompose_plot)

Description:

Seasonality is the best window to look at when analyzing this data because it had a very clear pattern. The data represents water that is coming from the mountains which experience defined high and low flows depending on the season. It is also see a change in precipitation and other weather events when looking at seasonality. As the graph above shows, there is a noticeable decrease in precipitation from January 2014 to January 2024. This type of pattern is important to analyze to better decide how Colorado should change it’s water usage as we already have a deficit of available water.